import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
  
@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter<HttpException> {
catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse();
    const request = ctx.getRequest();
    const status = exception.getStatus();

    const exceptionRes: any = exception.getResponse();
    const { error, message } = exceptionRes;

    console.log('%s %s 错误消息: %s', request.method, request.url, exception.message)
    
    response.status(status).json({
        status,
        timestamp: new Date().toLocaleString(),
        path: request.url,
        error,
        message,
    });
}
}